Skip to content

Add Btrfs fallback for other Linux distros - #956

Open
locnnil wants to merge 2 commits into
canonical:mainfrom
locnnil:add-btrfs-fallback
Open

locnnil wants to merge 2 commits into
canonical:mainfrom
locnnil:add-btrfs-fallback

Conversation

@locnnil

@locnnil locnnil commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

Enables Btrfs fallback for other Linux distributions.

ZFS is the preferred storage driver, but it isn't available everywhere: WSL, SUSE, Arch, Fedora, and other distributions may ship without it. Keying the fallback off the distribution name is too coarse; it assumes every non-Ubuntu host lacks ZFS and every Ubuntu-derived one has it, neither of which holds for Debian and its derivatives.

Instead, detect whether the host provides a usable ZFS kernel module, already loaded (present at /dev/zfs AND /sys/module/zfs ) or loadable for the running kernel per modules.dep(5) (/lib/modules/$(uname -r)/modules.dep) or modules.builtin (/lib/modules/$(uname -r)/modules.builtin) and keep ZFS only then, falling back to btrfs otherwise. Only the kernel module is checked: LXD ships as a snap that bundles the zpool/zfs userspace tools, so a loaded or loadable module is what actually determines usability from the host side, tested on Arch Linux and openSUSE tumbleweed.

Self-review quick check

  • Make decisions that cost a lot to reverse explicit in the PR description.
  • Avoid nested conditions.
  • Delete dead code and redundant comments. TODO: check if it is okay to delete isWSL()
  • Normalise symmetries by sticking to doing identical things identically.
// one way to handle errors
if err := f(); err != nil {
   ...
}

// one way to handle multiple returns
val, err := f()
if err != nil {
   ...
}
...
  • Check that coupled code elements, files, and directories are adjacent. For example, test data is stored as close as possible to a test.
  • Put variable declaration and initialisation together.
  • Divide large expressions into digestable and self-explanatory ones. Use multiple variables if required.
  • Put a blank line between two logically different chunks of code.
  • Follow the style guide for new error messages.

Docs

Procedure:

  • I have checked and added or updated relevant documentation.
  • I have checked and added or updated relevant release notes.
  • I have included the technical author in the review.

Content:

  • Headings and titles accurately describe the content.
  • New and updated pages include correct metadata.
  • Documentation tests are added or updated where applicable (for tutorial/ and how-to/ sections).
  • Documentation follows the style guide.
  • If needed, docs/.coverage.yaml updated, coverage tags added (.. artefact).

Or:

  • I confirm the PR has no implications for documentation.

@jonathan-conder

Copy link
Copy Markdown
Contributor

It looks to me like the way LXD does it is just trying to load the zfs module; maybe we should follow their lead on that

@jonathan-conder

Copy link
Copy Markdown
Contributor

I think we also need to be more careful about where we use the storagePoolDriver variable. Currently we can assume it's accurate, since whether the host is WSL or not is unlikely to change. The availability of the ZFS module can easily change, though; we need a separate mechanism to indicate "what's the current driver of the workshop pool."

@locnnil

locnnil commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

I think we also need to be more careful about where we use the storagePoolDriver variable. Currently we can assume it's accurate, since whether the host is WSL or not is unlikely to change. The availability of the ZFS module can easily change, though; we need a separate mechanism to indicate "what's the current driver of the workshop pool."

So, considering the case where ZFS was available when the pool was created but later stops being present, most likely because the user installed a different kernel that doesn't ship the ZFS module. What should we do with the now-unusable ZFS pool?

I can think of those options:

  • Put the daemon into a degraded state and add an actionable error message like "restore the ZFS-capable kernel, or remove the pool to recreate it as Btrfs"
  • Warn the user with an actionable message like "Old ZFS pool detected on system without support for ZFS on path <path-to-zfs-pool>" but create a new Btrfs pool under a different name.

I believe that the first option is better, right?

@jonathan-conder

Copy link
Copy Markdown
Contributor

I believe that the first option is better, right?

I agree, but we should not suggest removing the pool, it will probably break the workshops using it (if it's even possible to remove it). Instead maybe it's best to reinstall the Workshop snap.

We just need to test what actually happens in that scenario, maybe LXD will fail to start and we probably handle that already.

@locnnil

locnnil commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@jonathan-conder I've implemented the requested change in 54bf6dd, which stops assuming a fixed state for ZFS availability. I then tested the degraded-state behavior for the scenario where ZFS is present at first but later vanishes.

I ran this on an Ubuntu Resolute LXD VM, reproducing a workshop pool created on ZFS whose kernel module later becomes unavailable after a kernel change.

Reproduction

  1. Started with ZFS available, so the workshop pool was created on the zfs driver.
  2. Built and installed a .deb for a newer kernel (7.2.0-rc7) that doesn't ship the ZFS module.
  3. Removed the previous kernel and its ZFS module package (linux-main-modules-zfs-7.0.0-29-generic).
  4. Rebooted into the new kernel and ran workshop list.

Result

Instead of surfacing a raw LXD error, the daemon goes into degraded mode with an actionable message:

$ workshop list
error: system is not healthy: cannot use the "workshop" storage pool, its storage driver may be unavailable (for example a ZFS pool after booting a kernel without the ZFS module): Error loading "zfs" module: Failed running: modprobe -b zfs
: exit status 1 (modprobe: FATAL: Module zfs not found in directory /lib/modules/7.2.0-rc7)
Boot into a kernel that provides the pool's storage driver, or reinstall Workshop to recreate the pool on an available driver

Recovery

The ZFS pool can't be deleted through LXD while the module is missing (lxc storage delete loads the driver, which fails), so the recovery is to reinstall Workshop: this recreates the workshop pool on an available driver (Btrfs) for a host that no longer provides ZFS.

On adding a Spread test

Let me know if you think we should add a Spread test covering this case. Two caveats:

  • For my manual test I had to build and install an upstream kernel, since simply uninstalling linux-main-modules-zfs-7.0.0-xx-generic isn't enough to reproduce a realistic scenario. For an automated test we could instead force the broken state, making it reproducible by just forcefully removing a package.
  • The bigger drawback is that this would require Spread to run on LXD VMs instead of containers. That would be a significant change to the current testing infrastructure.

Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
inst.Devices = map[string]map[string]string{}
}
if err := mergeDevices(inst.Devices, snapshot.Sdks, name); err != nil {
usesZFS, err := poolUsesZFS(conn)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this adds an additional API call to these operations, do we have any info on the impact it has on latency? we could alternatively cache the storage pool driver at launch

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change cbe0b61 poolUsesZFS reads from a cached value.

@jonathan-conder

jonathan-conder commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

The ZFS pool can't be deleted through LXD while the module is missing (lxc storage delete loads the driver, which fails), so the recovery is to reinstall Workshop: this recreates the workshop pool on an available driver (Btrfs) for a host that no longer provides ZFS.

I don't see how reinstalling Workshop will help. If LXD is unable to delete the pool then it will still be there after the reinstall.

For my manual test I had to build and install an upstream kernel, since simply uninstalling linux-main-modules-zfs-7.0.0-xx-generic isn't enough to reproduce a realistic scenario. For an automated test we could instead force the broken state, making it reproducible by just forcefully removing a package.

It's not reasonable to do that in a test. It's a rare enough case that I think some manual recovery steps are OK.

The bigger drawback is that this would require Spread to run on LXD VMs instead of containers. That would be a significant change to the current testing infrastructure.

we already do this, it's not a change at all

@locnnil
locnnil force-pushed the add-btrfs-fallback branch 2 times, most recently from 2fcccdc to 949bc5e Compare August 28, 2026 22:48
@locnnil

locnnil commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

I don't see how reinstalling Workshop will help. If LXD is unable to delete the pool then it will still be there after the reinstall.

Yeah, I think in this case you would need to reinstall LXD and Workshop, but this seems too drastic. Anyway, I've tested, and when the ZFS-capable kernel is restored, the workshop will be working again.

Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Outdated
// re-querying LXD (which reloads the driver's module). The pool's driver is
// fixed at creation, so the cached value stays accurate for the daemon's run.
var poolDriverCache struct {
sync.RWMutex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a mutex here? I think anything that looks at the storage driver should run after the value has been initialised.

Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved

@jonathan-conder jonathan-conder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I think we're nearly there, just a couple of minor comments below, and I still think we should check for storagePoolDriver != existingPool.Driver in ensureBackendReady()

Comment thread docs/reference/workshops.rst Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
@locnnil
locnnil requested review from jonathan-conder and a lite review from Copilot October 6, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Critical storage-driver race and pool-validation issues remain, and fallback integration coverage is missing.

Review effort: Lite
Findings: 1 High severity · 2 Low severity

Open (3)
What changed in this PR

Adds dynamic ZFS-preferred storage selection with Btrfs fallback based on LXD capabilities, plus tests and documentation updates.

Changes:

  • Selects and tracks the storage pool driver.
  • Adds driver-selection test coverage and test exports.
  • Updates tutorial, reference, and architecture documentation.
File Summary
internal/​workshop/​lxd/​lxd_backend.go Implements storage-driver selection and pool initialization.
internal/​workshop/​lxd/​lxd_backend_test.go Tests preferred-driver selection and fallback behavior.
internal/​workshop/​lxd/​export_test.go Exposes driver-selection logic for tests.
docs/​tutorial/​part-1-get-started.rst Documents storage fallback prerequisites.
docs/​reference/​workshops.rst Updates storage-driver documentation.
docs/​explanation/​architecture/​components.rst Updates the storage architecture description.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread docs/reference/workshops.rst Resolved
Copilot AI lite review requested due to automatic review settings October 29, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Approval is blocked by an unresolved critical data race during LXD recovery, along with documentation inconsistencies about Btrfs capitalization and ZFS-only behavior.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Low severity Capitalize Btrfs consistently in user-facing documentation

docs/​explanation/​architecture/​components.rst:262

This prose uses lowercase btrfs, whereas the tutorial and the new code comment use Btrfs. Keep the filesystem name consistently capitalized in user-facing documentation; reserve lowercase for the LXD driver identifier.

3 resolved since last review

Review effort: Lite

Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Copilot AI lite review requested due to automatic review settings November 3, 2026 14:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Approval is blocked by an unresolved race that can expose a newly created ZFS pool before its driver is published, along with unsupported pre-existing pool acceptance and inconsistent backend-specific documentation.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

High severity Publish the pool driver before concurrent backend operations

internal/​workshop/​lxd/​lxd_backend.go:374

The atomic load/store removes the data race, but it does not close the publication window: after CreateStoragePool completes and before setPoolDriver runs, a concurrently executing task can enter mergeDevices or copyInstance and observe poolDriver() == "". On a newly created ZFS pool that omits initial.zfs.promote, so the first snapshot/copy can use the Btrfs path and fail or lose the required ZFS promotion. Publish the driver before the pool becomes usable, or serialize pool creation/recovery with backend operations.

Medium severity Reject existing pools with unsupported drivers

internal/​workshop/​lxd/​lxd_backend.go:408

When a workshop pool already exists and poolDriver() is still empty, this branch adopts whatever LXD driver it finds. That allows a pre-existing dir, lvm, or other pool to be silently accepted even though preferredDriver and the documented behavior only support ZFS and Btrfs; the snapshot behavior then no longer matches the backend's assumptions. Validate existingPool.Driver against the supported drivers before recording it (or return an actionable error).

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active critical issues remain, including an unused import that prevents compilation and insufficient validation of existing or unknown storage drivers, which can cause incorrect snapshot behavior.

5 open issues

Review effort: Lite

Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Copilot AI lite review requested due to automatic review settings November 5, 2026 15:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change leaves two active documentation inconsistencies: an unconditional ZFS/LZ4 capability claim on the Btrfs path and a contradictory developer prerequisite that still requires ZFS.

3 open issues
1 resolved since last review

Review effort: Lite

Comment on lines +263 to +264
with automatic btrfs fallback otherwise,
for example on Windows Subsystem for Linux (WSL).
Comment on lines 48 to +52
|ws_markup| is supported on Ubuntu
and other :program:`snap`-enabled Linux distributions;
it is also compatible with Windows Subsystem for Linux (WSL2),
where it uses Btrfs instead of ZFS for storage.
it is also compatible with Windows Subsystem for Linux (WSL2).
For storage, it uses ZFS where |ws_markup| detects that ZFS is available,
and otherwise falls back to btrfs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active documentation inconsistency and stale storage-driver caching remain unresolved, including a moderate correctness risk when recreating a deleted pool.

3 open issues
1 resolved since last review

Review effort: Lite

Comment thread internal/workshop/lxd/lxd_backend.go Resolved
Copilot AI lite review requested due to automatic review settings November 5, 2026 17:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The documentation remains internally contradictory because several sections still present ZFS as universal despite newly documented Btrfs support, leaving an active correctness issue to resolve.

3 open issues

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active documentation inconsistencies and a moderate recovery bug that can retain unavailable ZFS instead of selecting supported Btrfs require changes.

5 open issues

Review effort: Lite

Comment thread docs/contributing/development.rst Resolved
Comment thread docs/tutorial/part-1-get-started.rst Resolved
Copilot AI lite review requested due to automatic review settings November 11, 2026 19:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Active documentation issues remain: the driver name uses inconsistent btrfs capitalization, and the architecture diagram still describes the storage subsystem exclusively as ZFS despite documenting a Btrfs fallback.

2 open issues
3 resolved since last review

Review effort: Lite

Copilot AI lite review requested due to automatic review settings November 11, 2026 19:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The documentation still presents ZFS behavior as universal even though storage is now driver-dependent, leaving inaccurate explanations for the newly supported btrfs path.

2 open issues

Review effort: Lite

Copilot AI lite review requested due to automatic review settings November 11, 2026 19:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The change still has an unresolved critical backend issue where an existing unsupported storage pool can be accepted and cause later operations to fail, along with documentation that contradicts fallback behavior.

3 open issues

Review effort: Lite

Comment thread internal/workshop/lxd/lxd_backend.go Resolved
ZFS is preferred, but WSL, SUSE, Arch, Fedora and others may ship
without it. Instead of keying the fallback off WSL, pick the first
driver LXD reports as supported (ZFS, then Btrfs), and fail the system
check with a clear error if the pool is missing and neither is
available.

Record the pool's driver atomically, since it may be set after the
daemon starts serving. Adopt an existing pool's driver if it is ZFS or
Btrfs and reject anything else, recreate a missing pool on the
preferred supported driver, and serialize ensureBackendReady so
concurrent callers don't race to create the pool.

Update the docs to describe the detection-based fallback.

Closes: canonical#742

Signed-off-by: Lincoln Wallace <lincoln.wallace@canonical.com>

wip

Signed-off-by: Lincoln Wallace <lincoln.wallace@canonical.com>
Workshop no longer limits btrfs to WSL. It uses ZFS where LXD
supports it and falls back to btrfs otherwise. Update the tutorial,
reference, architecture and contributing pages to match.

Signed-off-by: Lincoln Wallace <lincoln.wallace@canonical.com>
Copilot AI lite review requested due to automatic review settings November 12, 2026 15:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Approval is blocked by an unaddressed compatibility failure in the snapshot integration suite for Btrfs, along with incorrect handling of pending or errored storage pools and contradictory documentation.

6 open issues
1 resolved since last review

Review effort: Lite

var (
storagePoolDriver = "zfs"
// storageDrivers lists the supported pool drivers, most preferred first.
storageDrivers = []string{"zfs", "btrfs"}
Comment on lines +218 to +220
if pool.Status == api.StoragePoolStatusUnvailable {
return fmt.Errorf("%q storage pool unavailable: LXD cannot initialize it with the %q driver", storagePool, pool.Driver)
}
Comment on lines +190 to +192
It uses ZFS on systems where |ws_markup| detects that ZFS is available,
and otherwise falls back to btrfs
(for example on Windows Subsystem for Linux).
Comment on lines +51 to +52
For storage, it uses ZFS where |ws_markup| detects that ZFS is available,
and otherwise falls back to btrfs.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

workshop does not work on non-Ubuntu systems

3 participants